package mutris.client.com;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.MultipleGradientPaint.CycleMethod;
import java.awt.RadialGradientPaint;
import java.awt.Rectangle;
import java.awt.geom.Point2D;
import java.util.HashMap;

import mutris.client.board.Block;
import mutris.client.board.BlockPoint;
import mutris.client.board.Board;

public class DefaultBlockPainter extends AbstractBlockPainter {

	static private final int RADIUS = 16;
	
	static private final HashMap<Block,DefaultGradientData> blockGradients;
	
	static {
		
		blockGradients = new HashMap<Block, DefaultGradientData>();

		blockGradients.put(Block.SINGLE, new DefaultGradientData(
				35, 
				new float[] {0.2f, 0.6f, 0.9f}, 
				new Color[] {new Color(255, 255, 255), new Color(200, 200, 200), new Color(100, 100, 100)}));

		blockGradients.put(Block.BAR, new DefaultGradientData(
				35, 
				new float[] {0.2f, 0.6f, 0.9f}, 
				new Color[] {new Color(200, 200, 255), new Color(100, 100, 200), new Color(30, 30, 180)}));
		
		blockGradients.put(Block.CUBE, new DefaultGradientData(
				35, 
				new float[] {0.2f, 0.6f, 0.9f}, 
				new Color[] {new Color(230, 200, 230), new Color(200, 100, 200), new Color(180, 30, 180)}));

		blockGradients.put(Block.CHAIR_LEFT, new DefaultGradientData(
				35, 
				new float[] {0.2f, 0.6f, 0.9f}, 
				new Color[] {new Color(255, 255, 100), new Color(200, 200, 100), new Color(180, 180, 30)}));

		blockGradients.put(Block.CHAIR_RIGHT, new DefaultGradientData(
				35, 
				new float[] {0.2f, 0.6f, 0.9f}, 
				new Color[] {new Color(100, 255, 100), new Color(100, 200, 100), new Color(30, 180, 30)}));

		blockGradients.put(Block.STAIR_LEFT, new DefaultGradientData(
				35, 
				new float[] {0.2f, 0.6f, 0.9f}, 
				new Color[] {new Color(255, 150, 150), new Color(200, 100, 100), new Color(180, 30, 30)}));

		blockGradients.put(Block.STAIR_RIGHT, new DefaultGradientData(
				35, 
				new float[] {0.2f, 0.6f, 0.9f}, 
				new Color[] {new Color(100, 255, 255), new Color(100, 200, 200), new Color(30, 180, 180)}));

		blockGradients.put(Block.PYRAMID, new DefaultGradientData(
				35, 
				new float[] {0.2f, 0.6f, 0.9f}, 
				new Color[] {new Color(255, 225, 200), new Color(240, 160, 30), new Color(210, 150, 20)}));

	}
	
	private static class DefaultGradientData {
	    float radius;
	    float[] dist;
	    Color[] colors;
	    
	    private DefaultGradientData(float radius, float[] dist, Color[] colors) {
	    	this.radius = radius;
	    	this.dist = dist;
	    	this.colors = colors;
	    }
	}
	
	
	@Override
	public void paint(BlockPoint p, Board board, Rectangle boundaries, Graphics2D g) {
		
		DefaultGradientData gdata = blockGradients.get(board.getBlock(p));
		
		Point2D center = new Point2D.Float(boundaries.x + 22, boundaries.y + 22);
	    Point2D focus = new Point2D.Float((float)center.getX() - 10, (float)center.getY() - 10);
	    RadialGradientPaint rgp = new RadialGradientPaint(center, gdata.radius, focus, gdata.dist, gdata.colors, CycleMethod.NO_CYCLE);
	    g.setPaint(rgp);

		//g.setColor(Color.blue);
		g.fillRoundRect(boundaries.x, boundaries.y, boundaries.width, boundaries.height, RADIUS, RADIUS);
		g.setColor(Color.gray);
		g.drawRoundRect(boundaries.x, boundaries.y, boundaries.width, boundaries.height, RADIUS, RADIUS);
	}

}
